package com.ayoka.parenting.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2015/7/9.
 */
public class DBHelper extends SQLiteOpenHelper {

    /**
     * 数据库名称 *
     */
    public static final String DATABASE_NAME = "ayokaClient.db";

    /**
     * 数据库版本 *
     */
    public static final int DATABASE_VERSION = 1;


    /**
     * 创建省市区地址表
     */
    private static final String SQL_CREATE_ENTITY_PCAS = "CREATE TABLE " + PCASEntity.TABLE_NAME + " ("
            + PCASEntity._ID + " INTEGER PRIMARY KEY, "
            + PCASEntity.COLUMN_LABEL + " TEXT NOT NULL, "
            + PCASEntity.COLUMN_PARENT + " TEXT NOT NULL, "
            + PCASEntity.COLUMN_VALUE + " TEXT NOT NULL)";

    /**
     * 删除省市区地址表
     */
    private static final String SQL_DELETE_ENTITY_PCAS = "DROP TABLE IF EXISTS "
            + PCASEntity.TABLE_NAME;


    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTITY_PCAS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTITY_PCAS);
        onCreate(db);
    }
}
